{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T03:24:06.750002Z",
     "start_time": "2019-10-30T03:24:06.746044Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.选取Series数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T03:25:35.818099Z",
     "start_time": "2019-10-30T03:25:35.731330Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Alabama A & M University                   Normal\n",
       "University of Alabama at Birmingham    Birmingham\n",
       "Amridge University                     Montgomery\n",
       "University of Alabama in Huntsville    Huntsville\n",
       "Alabama State University               Montgomery\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取college数据集，查看city的前5行\n",
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "city = college['CITY']\n",
    "city.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T03:26:43.825613Z",
     "start_time": "2019-10-30T03:26:43.818632Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Huntsville'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# iloc可以通过整数选取\n",
    "city.iloc[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T03:27:15.907994Z",
     "start_time": "2019-10-30T03:27:15.899052Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Birmingham Southern College                            Birmingham\n",
       "George C Wallace State Community College-Hanceville    Hanceville\n",
       "Judson College                                             Marion\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# iloc通过整数列表选取多行，返回结果是Series\n",
    "city.iloc[[10, 20, 30]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T03:28:10.721324Z",
     "start_time": "2019-10-30T03:28:10.713342Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Alabama State University              Montgomery\n",
       "Enterprise State Community College    Enterprise\n",
       "Heritage Christian University           Florence\n",
       "Marion Military Institute                 Marion\n",
       "Reid State Technical College           Evergreen\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选择等分的数据，可以使用切片语法\n",
    "city.iloc[4:50:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T03:28:37.210585Z",
     "start_time": "2019-10-30T03:28:37.201610Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Florence'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# loc只接收行索引标签\n",
    "city.loc['Heritage Christian University']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:06:22.349666Z",
     "start_time": "2019-10-30T06:06:22.340690Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Northwest HVAC/R Training Center',\n",
       " 'California State University-Dominguez Hills',\n",
       " 'Lower Columbia College',\n",
       " 'Southwest Acupuncture College-Boulder']"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 随机选择4个标签\n",
    "np.random.seed(1)\n",
    "labels = list(np.random.choice(city.index, 4))\n",
    "labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:07:14.528124Z",
     "start_time": "2019-10-30T06:07:14.516156Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Northwest HVAC/R Training Center                Spokane\n",
       "California State University-Dominguez Hills      Carson\n",
       "Lower Columbia College                         Longview\n",
       "Southwest Acupuncture College-Boulder           Boulder\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过标签列表选择多行\n",
    "city.loc[labels]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:08:40.885360Z",
     "start_time": "2019-10-30T06:08:40.876384Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Alabama State University              Montgomery\n",
       "Enterprise State Community College    Enterprise\n",
       "Heritage Christian University           Florence\n",
       "Marion Military Institute                 Marion\n",
       "Reid State Technical College           Evergreen\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 也可以通过切片语法均匀选择多个\n",
    "city.loc['Alabama State University':'Reid State Technical College':10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:20:45.066253Z",
     "start_time": "2019-10-30T06:20:45.057280Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Alabama State University              Montgomery\n",
       "Enterprise State Community College    Enterprise\n",
       "Heritage Christian University           Florence\n",
       "Marion Military Institute                 Marion\n",
       "Reid State Technical College           Evergreen\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 也可以不使用loc,直接使用类似Python的语法\n",
    "city['Alabama State University':'Reid State Technical College':10]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 更多"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:21:37.260670Z",
     "start_time": "2019-10-30T06:21:37.252694Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "University of Alabama in Huntsville    Huntsville\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 要想只选取一项，并保留其Series类型，则传入一个只包含一项的列表\n",
    "city.iloc[[3]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:23:09.760904Z",
     "start_time": "2019-10-30T06:23:09.750937Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Series([], Name: CITY, dtype: object)"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用loc切片时要注意，如果start索引再stop索引之后，则会返回空，并且不会报警\n",
    "city.loc['Reid State Technical College':'Alabama State University':10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:25:33.941573Z",
     "start_time": "2019-10-30T06:25:33.933594Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Series([], Name: CITY, dtype: object)"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city.iloc[50:40:1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:26:18.509382Z",
     "start_time": "2019-10-30T06:26:18.501405Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Reid State Technical College           Evergreen\n",
       "Marion Military Institute                 Marion\n",
       "Heritage Christian University           Florence\n",
       "Enterprise State Community College    Enterprise\n",
       "Alabama State University              Montgomery\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 也可以切片逆序选取\n",
    "city.loc['Reid State Technical College':'Alabama State University':-10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:26:35.227676Z",
     "start_time": "2019-10-30T06:26:35.220691Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "University of South Alabama                Mobile\n",
       "Shelton State Community College        Tuscaloosa\n",
       "Samford University                     Birmingham\n",
       "Reid State Technical College            Evergreen\n",
       "Alabama Southern Community College    Monroeville\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city.iloc[50:40:-2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.选取DataFrame的行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:27:52.588786Z",
     "start_time": "2019-10-30T06:27:52.444172Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>Normal</td>\n",
       "      <td>AL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>424.0</td>\n",
       "      <td>420.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4206.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0059</td>\n",
       "      <td>0.0138</td>\n",
       "      <td>0.0656</td>\n",
       "      <td>1</td>\n",
       "      <td>0.7356</td>\n",
       "      <td>0.8284</td>\n",
       "      <td>0.1049</td>\n",
       "      <td>30300</td>\n",
       "      <td>33888</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>Birmingham</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>570.0</td>\n",
       "      <td>565.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11383.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0368</td>\n",
       "      <td>0.0179</td>\n",
       "      <td>0.0100</td>\n",
       "      <td>0.2607</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3460</td>\n",
       "      <td>0.5214</td>\n",
       "      <td>0.2422</td>\n",
       "      <td>39700</td>\n",
       "      <td>21941.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>291.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.2715</td>\n",
       "      <td>0.4536</td>\n",
       "      <td>1</td>\n",
       "      <td>0.6801</td>\n",
       "      <td>0.7795</td>\n",
       "      <td>0.8540</td>\n",
       "      <td>40100</td>\n",
       "      <td>23370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>Huntsville</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>595.0</td>\n",
       "      <td>590.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5451.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "      <td>0.2146</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3072</td>\n",
       "      <td>0.4596</td>\n",
       "      <td>0.2640</td>\n",
       "      <td>45500</td>\n",
       "      <td>24097</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>425.0</td>\n",
       "      <td>430.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4811.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0098</td>\n",
       "      <td>0.0243</td>\n",
       "      <td>0.0137</td>\n",
       "      <td>0.0892</td>\n",
       "      <td>1</td>\n",
       "      <td>0.7347</td>\n",
       "      <td>0.7554</td>\n",
       "      <td>0.1270</td>\n",
       "      <td>26600</td>\n",
       "      <td>33118.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                           CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                 Normal     AL   1.0      0.0   \n",
       "University of Alabama at Birmingham  Birmingham     AL   0.0      0.0   \n",
       "Amridge University                   Montgomery     AL   0.0      0.0   \n",
       "University of Alabama in Huntsville  Huntsville     AL   0.0      0.0   \n",
       "Alabama State University             Montgomery     AL   1.0      0.0   \n",
       "\n",
       "                                     WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  \\\n",
       "INSTNM                                                                         \n",
       "Alabama A & M University                   0.0         0     424.0     420.0   \n",
       "University of Alabama at Birmingham        0.0         0     570.0     565.0   \n",
       "Amridge University                         0.0         1       NaN       NaN   \n",
       "University of Alabama in Huntsville        0.0         0     595.0     590.0   \n",
       "Alabama State University                   0.0         0     425.0     430.0   \n",
       "\n",
       "                                     DISTANCEONLY     UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                      ...              \n",
       "Alabama A & M University                      0.0   4206.0  ...     0.0000   \n",
       "University of Alabama at Birmingham           0.0  11383.0  ...     0.0368   \n",
       "Amridge University                            1.0    291.0  ...     0.0000   \n",
       "University of Alabama in Huntsville           0.0   5451.0  ...     0.0172   \n",
       "Alabama State University                      0.0   4811.0  ...     0.0098   \n",
       "\n",
       "                                     UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                         \n",
       "Alabama A & M University               0.0059     0.0138    0.0656         1   \n",
       "University of Alabama at Birmingham    0.0179     0.0100    0.2607         1   \n",
       "Amridge University                     0.0000     0.2715    0.4536         1   \n",
       "University of Alabama in Huntsville    0.0332     0.0350    0.2146         1   \n",
       "Alabama State University               0.0243     0.0137    0.0892         1   \n",
       "\n",
       "                                     PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                            \n",
       "Alabama A & M University              0.7356    0.8284   0.1049   \n",
       "University of Alabama at Birmingham   0.3460    0.5214   0.2422   \n",
       "Amridge University                    0.6801    0.7795   0.8540   \n",
       "University of Alabama in Huntsville   0.3072    0.4596   0.2640   \n",
       "Alabama State University              0.7347    0.7554   0.1270   \n",
       "\n",
       "                                     MD_EARN_WNE_P10  GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                    \n",
       "Alabama A & M University                       30300               33888  \n",
       "University of Alabama at Birmingham            39700             21941.5  \n",
       "Amridge University                             40100               23370  \n",
       "University of Alabama in Huntsville            45500               24097  \n",
       "Alabama State University                       26600             33118.5  \n",
       "\n",
       "[5 rows x 26 columns]"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 还是读取college数据集\n",
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "college.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:28:41.435842Z",
     "start_time": "2019-10-30T06:28:41.421880Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "CITY                  Anchorage\n",
       "STABBR                       AK\n",
       "HBCU                          0\n",
       "                        ...    \n",
       "UG25ABV                  0.4386\n",
       "MD_EARN_WNE_P10           42500\n",
       "GRAD_DEBT_MDN_SUPP      19449.5\n",
       "Name: University of Alaska Anchorage, Length: 26, dtype: object"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取第61行\n",
    "pd.options.display.max_rows = 6\n",
    "college.iloc[60]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:29:33.294157Z",
     "start_time": "2019-10-30T06:29:33.284187Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "CITY                  Anchorage\n",
       "STABBR                       AK\n",
       "HBCU                          0\n",
       "                        ...    \n",
       "UG25ABV                  0.4386\n",
       "MD_EARN_WNE_P10           42500\n",
       "GRAD_DEBT_MDN_SUPP      19449.5\n",
       "Name: University of Alaska Anchorage, Length: 26, dtype: object"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 也可以通过行标签选取\n",
    "college.loc['University of Alaska Anchorage']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:30:30.507184Z",
     "start_time": "2019-10-30T06:30:30.468260Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>University of Alaska Anchorage</th>\n",
       "      <td>Anchorage</td>\n",
       "      <td>AK</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>12865.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0980</td>\n",
       "      <td>0.0181</td>\n",
       "      <td>0.0457</td>\n",
       "      <td>0.4539</td>\n",
       "      <td>1</td>\n",
       "      <td>0.2385</td>\n",
       "      <td>0.2647</td>\n",
       "      <td>0.4386</td>\n",
       "      <td>42500</td>\n",
       "      <td>19449.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>International Academy of Hair Design</th>\n",
       "      <td>Tempe</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>188.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0160</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0638</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0.7185</td>\n",
       "      <td>0.7346</td>\n",
       "      <td>0.3905</td>\n",
       "      <td>22200</td>\n",
       "      <td>10556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>Huntsville</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>595.0</td>\n",
       "      <td>590.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5451.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "      <td>0.2146</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3072</td>\n",
       "      <td>0.4596</td>\n",
       "      <td>0.2640</td>\n",
       "      <td>45500</td>\n",
       "      <td>24097</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                   \n",
       "University of Alaska Anchorage         Anchorage     AK   0.0      0.0   \n",
       "International Academy of Hair Design       Tempe     AZ   0.0      0.0   \n",
       "University of Alabama in Huntsville   Huntsville     AL   0.0      0.0   \n",
       "\n",
       "                                      WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  \\\n",
       "INSTNM                                                                          \n",
       "University of Alaska Anchorage              0.0         0       NaN       NaN   \n",
       "International Academy of Hair Design        0.0         0       NaN       NaN   \n",
       "University of Alabama in Huntsville         0.0         0     595.0     590.0   \n",
       "\n",
       "                                      DISTANCEONLY     UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                       ...              \n",
       "University of Alaska Anchorage                 0.0  12865.0  ...     0.0980   \n",
       "International Academy of Hair Design           0.0    188.0  ...     0.0160   \n",
       "University of Alabama in Huntsville            0.0   5451.0  ...     0.0172   \n",
       "\n",
       "                                      UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                          \n",
       "University of Alaska Anchorage          0.0181     0.0457    0.4539         1   \n",
       "International Academy of Hair Design    0.0000     0.0638    0.0000         0   \n",
       "University of Alabama in Huntsville     0.0332     0.0350    0.2146         1   \n",
       "\n",
       "                                      PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                             \n",
       "University of Alaska Anchorage         0.2385    0.2647   0.4386   \n",
       "International Academy of Hair Design   0.7185    0.7346   0.3905   \n",
       "University of Alabama in Huntsville    0.3072    0.4596   0.2640   \n",
       "\n",
       "                                      MD_EARN_WNE_P10  GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                     \n",
       "University of Alaska Anchorage                  42500             19449.5  \n",
       "International Academy of Hair Design            22200               10556  \n",
       "University of Alabama in Huntsville             45500               24097  \n",
       "\n",
       "[3 rows x 26 columns]"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取多个不连续的行\n",
    "college.iloc[[60, 99, 3]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:30:58.821435Z",
     "start_time": "2019-10-30T06:30:58.780541Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>University of Alaska Anchorage</th>\n",
       "      <td>Anchorage</td>\n",
       "      <td>AK</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>12865.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0980</td>\n",
       "      <td>0.0181</td>\n",
       "      <td>0.0457</td>\n",
       "      <td>0.4539</td>\n",
       "      <td>1</td>\n",
       "      <td>0.2385</td>\n",
       "      <td>0.2647</td>\n",
       "      <td>0.4386</td>\n",
       "      <td>42500</td>\n",
       "      <td>19449.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>International Academy of Hair Design</th>\n",
       "      <td>Tempe</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>188.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0160</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0638</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0.7185</td>\n",
       "      <td>0.7346</td>\n",
       "      <td>0.3905</td>\n",
       "      <td>22200</td>\n",
       "      <td>10556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>Huntsville</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>595.0</td>\n",
       "      <td>590.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5451.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "      <td>0.2146</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3072</td>\n",
       "      <td>0.4596</td>\n",
       "      <td>0.2640</td>\n",
       "      <td>45500</td>\n",
       "      <td>24097</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                   \n",
       "University of Alaska Anchorage         Anchorage     AK   0.0      0.0   \n",
       "International Academy of Hair Design       Tempe     AZ   0.0      0.0   \n",
       "University of Alabama in Huntsville   Huntsville     AL   0.0      0.0   \n",
       "\n",
       "                                      WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  \\\n",
       "INSTNM                                                                          \n",
       "University of Alaska Anchorage              0.0         0       NaN       NaN   \n",
       "International Academy of Hair Design        0.0         0       NaN       NaN   \n",
       "University of Alabama in Huntsville         0.0         0     595.0     590.0   \n",
       "\n",
       "                                      DISTANCEONLY     UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                       ...              \n",
       "University of Alaska Anchorage                 0.0  12865.0  ...     0.0980   \n",
       "International Academy of Hair Design           0.0    188.0  ...     0.0160   \n",
       "University of Alabama in Huntsville            0.0   5451.0  ...     0.0172   \n",
       "\n",
       "                                      UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                          \n",
       "University of Alaska Anchorage          0.0181     0.0457    0.4539         1   \n",
       "International Academy of Hair Design    0.0000     0.0638    0.0000         0   \n",
       "University of Alabama in Huntsville     0.0332     0.0350    0.2146         1   \n",
       "\n",
       "                                      PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                             \n",
       "University of Alaska Anchorage         0.2385    0.2647   0.4386   \n",
       "International Academy of Hair Design   0.7185    0.7346   0.3905   \n",
       "University of Alabama in Huntsville    0.3072    0.4596   0.2640   \n",
       "\n",
       "                                      MD_EARN_WNE_P10  GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                     \n",
       "University of Alaska Anchorage                  42500             19449.5  \n",
       "International Academy of Hair Design            22200               10556  \n",
       "University of Alabama in Huntsville             45500               24097  \n",
       "\n",
       "[3 rows x 26 columns]"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 也可以用loc加列表来选取\n",
    "labels = ['University of Alaska Anchorage','International Academy of Hair Design','University of Alabama in Huntsville']\n",
    "college.loc[labels]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:31:22.991794Z",
     "start_time": "2019-10-30T06:31:22.948912Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>International Academy of Hair Design</th>\n",
       "      <td>Tempe</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>188.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0160</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0638</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0.7185</td>\n",
       "      <td>0.7346</td>\n",
       "      <td>0.3905</td>\n",
       "      <td>22200</td>\n",
       "      <td>10556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GateWay Community College</th>\n",
       "      <td>Phoenix</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5211.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0127</td>\n",
       "      <td>0.0161</td>\n",
       "      <td>0.0702</td>\n",
       "      <td>0.7465</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3270</td>\n",
       "      <td>0.2189</td>\n",
       "      <td>0.5832</td>\n",
       "      <td>29800</td>\n",
       "      <td>7283</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Mesa Community College</th>\n",
       "      <td>Mesa</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>19055.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0205</td>\n",
       "      <td>0.0257</td>\n",
       "      <td>0.0682</td>\n",
       "      <td>0.6457</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3423</td>\n",
       "      <td>0.2207</td>\n",
       "      <td>0.4010</td>\n",
       "      <td>35200</td>\n",
       "      <td>8000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                \n",
       "International Academy of Hair Design    Tempe     AZ   0.0      0.0   \n",
       "GateWay Community College             Phoenix     AZ   0.0      0.0   \n",
       "Mesa Community College                   Mesa     AZ   0.0      0.0   \n",
       "\n",
       "                                      WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  \\\n",
       "INSTNM                                                                          \n",
       "International Academy of Hair Design        0.0         0       NaN       NaN   \n",
       "GateWay Community College                   0.0         0       NaN       NaN   \n",
       "Mesa Community College                      0.0         0       NaN       NaN   \n",
       "\n",
       "                                      DISTANCEONLY     UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                       ...              \n",
       "International Academy of Hair Design           0.0    188.0  ...     0.0160   \n",
       "GateWay Community College                      0.0   5211.0  ...     0.0127   \n",
       "Mesa Community College                         0.0  19055.0  ...     0.0205   \n",
       "\n",
       "                                      UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                          \n",
       "International Academy of Hair Design    0.0000     0.0638    0.0000         0   \n",
       "GateWay Community College               0.0161     0.0702    0.7465         1   \n",
       "Mesa Community College                  0.0257     0.0682    0.6457         1   \n",
       "\n",
       "                                      PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                             \n",
       "International Academy of Hair Design   0.7185    0.7346   0.3905   \n",
       "GateWay Community College              0.3270    0.2189   0.5832   \n",
       "Mesa Community College                 0.3423    0.2207   0.4010   \n",
       "\n",
       "                                      MD_EARN_WNE_P10  GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                     \n",
       "International Academy of Hair Design            22200               10556  \n",
       "GateWay Community College                       29800                7283  \n",
       "Mesa Community College                          35200                8000  \n",
       "\n",
       "[3 rows x 26 columns]"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# iloc可以用切片连续选取\n",
    "college.iloc[99:102]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:31:39.387944Z",
     "start_time": "2019-10-30T06:31:39.349049Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>International Academy of Hair Design</th>\n",
       "      <td>Tempe</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>188.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0160</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0638</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0.7185</td>\n",
       "      <td>0.7346</td>\n",
       "      <td>0.3905</td>\n",
       "      <td>22200</td>\n",
       "      <td>10556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GateWay Community College</th>\n",
       "      <td>Phoenix</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5211.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0127</td>\n",
       "      <td>0.0161</td>\n",
       "      <td>0.0702</td>\n",
       "      <td>0.7465</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3270</td>\n",
       "      <td>0.2189</td>\n",
       "      <td>0.5832</td>\n",
       "      <td>29800</td>\n",
       "      <td>7283</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Mesa Community College</th>\n",
       "      <td>Mesa</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>19055.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0205</td>\n",
       "      <td>0.0257</td>\n",
       "      <td>0.0682</td>\n",
       "      <td>0.6457</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3423</td>\n",
       "      <td>0.2207</td>\n",
       "      <td>0.4010</td>\n",
       "      <td>35200</td>\n",
       "      <td>8000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                \n",
       "International Academy of Hair Design    Tempe     AZ   0.0      0.0   \n",
       "GateWay Community College             Phoenix     AZ   0.0      0.0   \n",
       "Mesa Community College                   Mesa     AZ   0.0      0.0   \n",
       "\n",
       "                                      WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  \\\n",
       "INSTNM                                                                          \n",
       "International Academy of Hair Design        0.0         0       NaN       NaN   \n",
       "GateWay Community College                   0.0         0       NaN       NaN   \n",
       "Mesa Community College                      0.0         0       NaN       NaN   \n",
       "\n",
       "                                      DISTANCEONLY     UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                       ...              \n",
       "International Academy of Hair Design           0.0    188.0  ...     0.0160   \n",
       "GateWay Community College                      0.0   5211.0  ...     0.0127   \n",
       "Mesa Community College                         0.0  19055.0  ...     0.0205   \n",
       "\n",
       "                                      UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                          \n",
       "International Academy of Hair Design    0.0000     0.0638    0.0000         0   \n",
       "GateWay Community College               0.0161     0.0702    0.7465         1   \n",
       "Mesa Community College                  0.0257     0.0682    0.6457         1   \n",
       "\n",
       "                                      PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                             \n",
       "International Academy of Hair Design   0.7185    0.7346   0.3905   \n",
       "GateWay Community College              0.3270    0.2189   0.5832   \n",
       "Mesa Community College                 0.3423    0.2207   0.4010   \n",
       "\n",
       "                                      MD_EARN_WNE_P10  GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                     \n",
       "International Academy of Hair Design            22200               10556  \n",
       "GateWay Community College                       29800                7283  \n",
       "Mesa Community College                          35200                8000  \n",
       "\n",
       "[3 rows x 26 columns]"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# loc可以用标签连续选取\n",
    "start = 'International Academy of Hair Design'\n",
    "stop = 'Mesa Community College'\n",
    "college.loc[start:stop]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 更多"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:34:07.942957Z",
     "start_time": "2019-10-30T06:34:07.935977Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['University of Alaska Anchorage',\n",
       " 'International Academy of Hair Design',\n",
       " 'University of Alabama in Huntsville']"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# index.tolist（）可以直接提取索引标签，生成一个列表\n",
    "college.iloc[[60, 99, 3]].index.tolist()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.同时选取DataFrame的行和列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:38:48.539528Z",
     "start_time": "2019-10-30T06:38:48.447773Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>Normal</td>\n",
       "      <td>AL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>Birmingham</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                           CITY STABBR  HBCU  MENONLY\n",
       "INSTNM                                                               \n",
       "Alabama A & M University                 Normal     AL   1.0      0.0\n",
       "University of Alabama at Birmingham  Birmingham     AL   0.0      0.0\n",
       "Amridge University                   Montgomery     AL   0.0      0.0"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取college数据集，给行索引命名为INSTNM；选取前3行和前4列\n",
    "In[23]: college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "college.iloc[:3, :4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:39:20.897997Z",
     "start_time": "2019-10-30T06:39:20.884029Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>Normal</td>\n",
       "      <td>AL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>Birmingham</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                           CITY STABBR  HBCU  MENONLY\n",
       "INSTNM                                                               \n",
       "Alabama A & M University                 Normal     AL   1.0      0.0\n",
       "University of Alabama at Birmingham  Birmingham     AL   0.0      0.0\n",
       "Amridge University                   Montgomery     AL   0.0      0.0"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用loc实现同上功能\n",
    "college.loc[:'Amridge University', :'MENONLY']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:44:10.893878Z",
     "start_time": "2019-10-30T06:44:10.879919Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>SATVRMID</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.0</td>\n",
       "      <td>424.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.0</td>\n",
       "      <td>570.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.0</td>\n",
       "      <td>595.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.0</td>\n",
       "      <td>425.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     WOMENONLY  SATVRMID\n",
       "INSTNM                                                  \n",
       "Alabama A & M University                   0.0     424.0\n",
       "University of Alabama at Birmingham        0.0     570.0\n",
       "Amridge University                         0.0       NaN\n",
       "University of Alabama in Huntsville        0.0     595.0\n",
       "Alabama State University                   0.0     425.0"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取两列所有的行\n",
    "college.iloc[:, [4, 6]].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:44:34.092842Z",
     "start_time": "2019-10-30T06:44:34.075885Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>SATVRMID</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.0</td>\n",
       "      <td>424.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.0</td>\n",
       "      <td>570.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>National Personal Training Institute of Cleveland</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bay Area Medical Academy - San Jose Satellite Location</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Excel Learning Center-San Antonio South</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>7535 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                    WOMENONLY  SATVRMID\n",
       "INSTNM                                                                 \n",
       "Alabama A & M University                                  0.0     424.0\n",
       "University of Alabama at Birmingham                       0.0     570.0\n",
       "Amridge University                                        0.0       NaN\n",
       "...                                                       ...       ...\n",
       "National Personal Training Institute of Cleveland         NaN       NaN\n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN       NaN\n",
       "Excel Learning Center-San Antonio South                   NaN       NaN\n",
       "\n",
       "[7535 rows x 2 columns]"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# loc实现同上功能\n",
    "college.loc[:, ['WOMENONLY', 'SATVRMID']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:45:26.916570Z",
     "start_time": "2019-10-30T06:45:26.904604Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>GateWay Community College</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0029</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>American Baptist Seminary of the West</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                       SATMTMID  UGDS_NHPI\n",
       "INSTNM                                                    \n",
       "GateWay Community College                   NaN     0.0029\n",
       "American Baptist Seminary of the West       NaN        NaN"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取不连续的行和列\n",
    "college.iloc[[100,200], [7, 15]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:53:17.057285Z",
     "start_time": "2019-10-30T06:53:17.039331Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>GateWay Community College</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0029</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>American Baptist Seminary of the West</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                       SATMTMID  UGDS_NHPI\n",
       "INSTNM                                                    \n",
       "GateWay Community College                   NaN     0.0029\n",
       "American Baptist Seminary of the West       NaN        NaN"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用loc和列表，选取不连续的行和列\n",
    "rows = ['GateWay Community College', 'American Baptist Seminary of the West']\n",
    "columns = ['SATMTMID', 'UGDS_NHPI']\n",
    "college.loc[rows, columns]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:53:51.201969Z",
     "start_time": "2019-10-30T06:53:51.194989Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.401"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# iloc选取一个标量值\n",
    "college.iloc[5, -4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:54:10.273964Z",
     "start_time": "2019-10-30T06:54:10.267981Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.401"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# loc选取一个标量值\n",
    "college.loc['The University of Alabama', 'PCTFLOAN']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T06:59:36.715440Z",
     "start_time": "2019-10-30T06:59:36.708455Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Empire Beauty School-Flagstaff     0\n",
       "Charles of Italy Beauty College    0\n",
       "Central Arizona College            0\n",
       "University of Arizona              0\n",
       "Arizona State University-Tempe     0\n",
       "Name: RELAFFIL, dtype: int64"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# iloc对行切片，并只选取一列\n",
    "college.iloc[90:80:-2, 5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:01:01.663260Z",
     "start_time": "2019-10-30T07:01:01.653321Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Empire Beauty School-Flagstaff     0\n",
       "Charles of Italy Beauty College    0\n",
       "Central Arizona College            0\n",
       "University of Arizona              0\n",
       "Arizona State University-Tempe     0\n",
       "Name: RELAFFIL, dtype: int64"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# loc对行切片，并只选取一列\n",
    "start = 'Empire Beauty School-Flagstaff'\n",
    "stop = 'Arizona State University-Tempe'\n",
    "college.loc[start:stop:-2, 'RELAFFIL']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.用整数和标签选取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:22:08.108576Z",
     "start_time": "2019-10-30T07:22:08.035773Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10, 19)"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取college数据集，行索引命名为INSTNM\n",
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "# 用索引方法get_loc,找到指定列的整数位置\n",
    "col_start = college.columns.get_loc('UGDS_WHITE')\n",
    "col_end = college.columns.get_loc('UGDS_UNKN') + 1\n",
    "col_start, col_end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:22:50.697688Z",
     "start_time": "2019-10-30T07:22:50.677734Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.0333</td>\n",
       "      <td>0.9353</td>\n",
       "      <td>0.0055</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0024</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0059</td>\n",
       "      <td>0.0138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.5922</td>\n",
       "      <td>0.2600</td>\n",
       "      <td>0.0283</td>\n",
       "      <td>0.0518</td>\n",
       "      <td>0.0022</td>\n",
       "      <td>0.0007</td>\n",
       "      <td>0.0368</td>\n",
       "      <td>0.0179</td>\n",
       "      <td>0.0100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.2990</td>\n",
       "      <td>0.4192</td>\n",
       "      <td>0.0069</td>\n",
       "      <td>0.0034</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.2715</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.6988</td>\n",
       "      <td>0.1255</td>\n",
       "      <td>0.0382</td>\n",
       "      <td>0.0376</td>\n",
       "      <td>0.0143</td>\n",
       "      <td>0.0002</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.0158</td>\n",
       "      <td>0.9208</td>\n",
       "      <td>0.0121</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0010</td>\n",
       "      <td>0.0006</td>\n",
       "      <td>0.0098</td>\n",
       "      <td>0.0243</td>\n",
       "      <td>0.0137</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                 0.0333      0.9353     0.0055   \n",
       "University of Alabama at Birmingham      0.5922      0.2600     0.0283   \n",
       "Amridge University                       0.2990      0.4192     0.0069   \n",
       "University of Alabama in Huntsville      0.6988      0.1255     0.0382   \n",
       "Alabama State University                 0.0158      0.9208     0.0121   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                 0.0019     0.0024     0.0019   \n",
       "University of Alabama at Birmingham      0.0518     0.0022     0.0007   \n",
       "Amridge University                       0.0034     0.0000     0.0000   \n",
       "University of Alabama in Huntsville      0.0376     0.0143     0.0002   \n",
       "Alabama State University                 0.0019     0.0010     0.0006   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                0.0000    0.0059     0.0138  \n",
       "University of Alabama at Birmingham     0.0368    0.0179     0.0100  \n",
       "Amridge University                      0.0000    0.0000     0.2715  \n",
       "University of Alabama in Huntsville     0.0172    0.0332     0.0350  \n",
       "Alabama State University                0.0098    0.0243     0.0137  "
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用切片选取连续的列\n",
    "college.iloc[:5, col_start:col_end]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 更多"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:25:33.922168Z",
     "start_time": "2019-10-30T07:25:33.895241Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Birmingham Southern College</th>\n",
       "      <td>0.7983</td>\n",
       "      <td>0.1102</td>\n",
       "      <td>0.0195</td>\n",
       "      <td>0.0517</td>\n",
       "      <td>0.0102</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0051</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0051</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chattahoochee Valley Community College</th>\n",
       "      <td>0.4661</td>\n",
       "      <td>0.4372</td>\n",
       "      <td>0.0492</td>\n",
       "      <td>0.0127</td>\n",
       "      <td>0.0023</td>\n",
       "      <td>0.0035</td>\n",
       "      <td>0.0151</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Concordia College Alabama</th>\n",
       "      <td>0.0280</td>\n",
       "      <td>0.8758</td>\n",
       "      <td>0.0373</td>\n",
       "      <td>0.0093</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0031</td>\n",
       "      <td>0.0466</td>\n",
       "      <td>0.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South University-Montgomery</th>\n",
       "      <td>0.3046</td>\n",
       "      <td>0.6054</td>\n",
       "      <td>0.0153</td>\n",
       "      <td>0.0153</td>\n",
       "      <td>0.0153</td>\n",
       "      <td>0.0096</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Enterprise State Community College</th>\n",
       "      <td>0.6408</td>\n",
       "      <td>0.2435</td>\n",
       "      <td>0.0509</td>\n",
       "      <td>0.0202</td>\n",
       "      <td>0.0081</td>\n",
       "      <td>0.0029</td>\n",
       "      <td>0.0254</td>\n",
       "      <td>0.0012</td>\n",
       "      <td>0.0069</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>James H Faulkner State Community College</th>\n",
       "      <td>0.6979</td>\n",
       "      <td>0.2259</td>\n",
       "      <td>0.0320</td>\n",
       "      <td>0.0084</td>\n",
       "      <td>0.0177</td>\n",
       "      <td>0.0014</td>\n",
       "      <td>0.0152</td>\n",
       "      <td>0.0007</td>\n",
       "      <td>0.0009</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                          UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                        \n",
       "Birmingham Southern College                   0.7983      0.1102     0.0195   \n",
       "Chattahoochee Valley Community College        0.4661      0.4372     0.0492   \n",
       "Concordia College Alabama                     0.0280      0.8758     0.0373   \n",
       "South University-Montgomery                   0.3046      0.6054     0.0153   \n",
       "Enterprise State Community College            0.6408      0.2435     0.0509   \n",
       "James H Faulkner State Community College      0.6979      0.2259     0.0320   \n",
       "\n",
       "                                          UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                       \n",
       "Birmingham Southern College                   0.0517     0.0102     0.0000   \n",
       "Chattahoochee Valley Community College        0.0127     0.0023     0.0035   \n",
       "Concordia College Alabama                     0.0093     0.0000     0.0000   \n",
       "South University-Montgomery                   0.0153     0.0153     0.0096   \n",
       "Enterprise State Community College            0.0202     0.0081     0.0029   \n",
       "James H Faulkner State Community College      0.0084     0.0177     0.0014   \n",
       "\n",
       "                                          UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                                    \n",
       "Birmingham Southern College                  0.0051    0.0000     0.0051  \n",
       "Chattahoochee Valley Community College       0.0151    0.0000     0.0139  \n",
       "Concordia College Alabama                    0.0031    0.0466     0.0000  \n",
       "South University-Montgomery                  0.0000    0.0019     0.0326  \n",
       "Enterprise State Community College           0.0254    0.0012     0.0069  \n",
       "James H Faulkner State Community College     0.0152    0.0007     0.0009  "
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# index（）方法可以获得整数行对应的标签名\n",
    "row_start = college.index[10]\n",
    "row_end = college.index[15]\n",
    "row_start, row_end\n",
    "college.loc[row_start:row_end, 'UGDS_WHITE':'UGDS_UNKN']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5.快速选取标量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:27:15.374854Z",
     "start_time": "2019-10-30T07:27:15.300053Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6609999999999999"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过将行标签赋值给一个变量，用loc选取\n",
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "cn = 'Texas A & M University-College Station'\n",
    "college.loc[cn, 'UGDS_WHITE']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:35:43.623914Z",
     "start_time": "2019-10-30T07:35:43.612942Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6609999999999999"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# at可以实现同样的功能\n",
    "college.at[cn, 'UGDS_WHITE']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:36:27.927437Z",
     "start_time": "2019-10-30T07:36:19.546844Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10.1 µs ± 224 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
    "# 用魔术方法%timeit,对速度进行比较\n",
    "%timeit college.loc[cn, 'UGDS_WHITE']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:36:42.521404Z",
     "start_time": "2019-10-30T07:36:36.899440Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6.96 µs ± 349 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit college.at[cn, 'UGDS_WHITE']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### .iat 和 .at 只接收标量值，是专门用来取代 .iloc 和 .loc 选取标量的，可以节省大概2.5微秒。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:38:11.130436Z",
     "start_time": "2019-10-30T07:38:11.122460Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3765, 10)"
      ]
     },
     "execution_count": 128,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用get_loc找到整数位置，再进行速度比较\n",
    "row_num = college.index.get_loc(cn)\n",
    "col_num = college.columns.get_loc('UGDS_WHITE')\n",
    "row_num, col_num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:38:30.767918Z",
     "start_time": "2019-10-30T07:38:20.988074Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12 µs ± 199 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit college.iloc[row_num, col_num]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:38:39.098641Z",
     "start_time": "2019-10-30T07:38:33.023885Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7.47 µs ± 307 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit college.iat[row_num, col_num]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:39:04.168594Z",
     "start_time": "2019-10-30T07:38:54.203246Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12.2 µs ± 387 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit college.iloc[5, col_num]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:39:10.908602Z",
     "start_time": "2019-10-30T07:39:04.287278Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8.03 µs ± 757 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit college.iat[5, col_num]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 更多"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:39:59.195438Z",
     "start_time": "2019-10-30T07:39:59.188455Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'IL'"
      ]
     },
     "execution_count": 133,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Series对象也可以使用.iat和.at选取标量\n",
    "state = college['STABBR']\n",
    "state.iat[1000]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:40:19.923006Z",
     "start_time": "2019-10-30T07:40:19.917021Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'CA'"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "state.at['Stanford University']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.惰性行切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:41:16.240396Z",
     "start_time": "2019-10-30T07:41:16.131688Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Birmingham Southern College</th>\n",
       "      <td>Birmingham</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>560.0</td>\n",
       "      <td>560.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1180.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0051</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0051</td>\n",
       "      <td>0.0017</td>\n",
       "      <td>1</td>\n",
       "      <td>0.1920</td>\n",
       "      <td>0.4809</td>\n",
       "      <td>0.0152</td>\n",
       "      <td>44200</td>\n",
       "      <td>27000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Concordia College Alabama</th>\n",
       "      <td>Selma</td>\n",
       "      <td>AL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>420.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>322.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0031</td>\n",
       "      <td>0.0466</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.1056</td>\n",
       "      <td>1</td>\n",
       "      <td>0.8667</td>\n",
       "      <td>0.9333</td>\n",
       "      <td>0.2367</td>\n",
       "      <td>19900</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Enterprise State Community College</th>\n",
       "      <td>Enterprise</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1729.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0254</td>\n",
       "      <td>0.0012</td>\n",
       "      <td>0.0069</td>\n",
       "      <td>0.3823</td>\n",
       "      <td>1</td>\n",
       "      <td>0.4895</td>\n",
       "      <td>0.2263</td>\n",
       "      <td>0.3399</td>\n",
       "      <td>24600</td>\n",
       "      <td>8273</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Faulkner University</th>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2367.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0173</td>\n",
       "      <td>0.0182</td>\n",
       "      <td>0.0258</td>\n",
       "      <td>0.2302</td>\n",
       "      <td>1</td>\n",
       "      <td>0.5812</td>\n",
       "      <td>0.7253</td>\n",
       "      <td>0.4589</td>\n",
       "      <td>37200</td>\n",
       "      <td>22000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New Beginning College of Cosmetology</th>\n",
       "      <td>Albertville</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>115.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0783</td>\n",
       "      <td>1</td>\n",
       "      <td>0.8224</td>\n",
       "      <td>0.8553</td>\n",
       "      <td>0.3933</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5500</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                             CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                    \n",
       "Birmingham Southern College            Birmingham     AL   0.0      0.0   \n",
       "Concordia College Alabama                   Selma     AL   1.0      0.0   \n",
       "Enterprise State Community College     Enterprise     AL   0.0      0.0   \n",
       "Faulkner University                    Montgomery     AL   0.0      0.0   \n",
       "New Beginning College of Cosmetology  Albertville     AL   0.0      0.0   \n",
       "\n",
       "                                      WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  \\\n",
       "INSTNM                                                                          \n",
       "Birmingham Southern College                 0.0         1     560.0     560.0   \n",
       "Concordia College Alabama                   0.0         1     420.0     400.0   \n",
       "Enterprise State Community College          0.0         0       NaN       NaN   \n",
       "Faulkner University                         0.0         1       NaN       NaN   \n",
       "New Beginning College of Cosmetology        0.0         0       NaN       NaN   \n",
       "\n",
       "                                      DISTANCEONLY    UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                      ...              \n",
       "Birmingham Southern College                    0.0  1180.0  ...     0.0051   \n",
       "Concordia College Alabama                      0.0   322.0  ...     0.0031   \n",
       "Enterprise State Community College             0.0  1729.0  ...     0.0254   \n",
       "Faulkner University                            0.0  2367.0  ...     0.0173   \n",
       "New Beginning College of Cosmetology           0.0   115.0  ...     0.0000   \n",
       "\n",
       "                                      UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                          \n",
       "Birmingham Southern College             0.0000     0.0051    0.0017         1   \n",
       "Concordia College Alabama               0.0466     0.0000    0.1056         1   \n",
       "Enterprise State Community College      0.0012     0.0069    0.3823         1   \n",
       "Faulkner University                     0.0182     0.0258    0.2302         1   \n",
       "New Beginning College of Cosmetology    0.0000     0.0000    0.0783         1   \n",
       "\n",
       "                                      PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                             \n",
       "Birmingham Southern College            0.1920    0.4809   0.0152   \n",
       "Concordia College Alabama              0.8667    0.9333   0.2367   \n",
       "Enterprise State Community College     0.4895    0.2263   0.3399   \n",
       "Faulkner University                    0.5812    0.7253   0.4589   \n",
       "New Beginning College of Cosmetology   0.8224    0.8553   0.3933   \n",
       "\n",
       "                                      MD_EARN_WNE_P10  GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                     \n",
       "Birmingham Southern College                     44200               27000  \n",
       "Concordia College Alabama                       19900   PrivacySuppressed  \n",
       "Enterprise State Community College              24600                8273  \n",
       "Faulkner University                             37200               22000  \n",
       "New Beginning College of Cosmetology              NaN                5500  \n",
       "\n",
       "[5 rows x 26 columns]"
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取college数据集；从行索引10到20，每隔一个取一行\n",
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "college[10:20:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:41:44.059000Z",
     "start_time": "2019-10-30T07:41:44.052020Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Birmingham Southern College              Birmingham\n",
       "Concordia College Alabama                     Selma\n",
       "Enterprise State Community College       Enterprise\n",
       "Faulkner University                      Montgomery\n",
       "New Beginning College of Cosmetology    Albertville\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 136,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Series也可以进行同样的切片\n",
    "city = college['CITY']\n",
    "city[10:20:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T07:42:42.377040Z",
     "start_time": "2019-10-30T07:42:42.371055Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Spokane Community College'"
      ]
     },
     "execution_count": 137,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看第4002个行索引标签\n",
    "college.index[4001]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T09:07:42.986695Z",
     "start_time": "2019-10-30T09:07:42.894939Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Mesa Community College</th>\n",
       "      <td>Mesa</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>19055.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0205</td>\n",
       "      <td>0.0257</td>\n",
       "      <td>0.0682</td>\n",
       "      <td>0.6457</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3423</td>\n",
       "      <td>0.2207</td>\n",
       "      <td>0.4010</td>\n",
       "      <td>35200</td>\n",
       "      <td>8000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hair Academy Inc-New Carrollton</th>\n",
       "      <td>New Carrollton</td>\n",
       "      <td>MD</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>504.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.4683</td>\n",
       "      <td>1</td>\n",
       "      <td>0.9756</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.5882</td>\n",
       "      <td>15200</td>\n",
       "      <td>9666</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>National College of Natural Medicine</th>\n",
       "      <td>Portland</td>\n",
       "      <td>OR</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                       \n",
       "Mesa Community College                          Mesa     AZ   0.0      0.0   \n",
       "Hair Academy Inc-New Carrollton       New Carrollton     MD   0.0      0.0   \n",
       "National College of Natural Medicine        Portland     OR   0.0      0.0   \n",
       "\n",
       "                                      WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  \\\n",
       "INSTNM                                                                          \n",
       "Mesa Community College                      0.0         0       NaN       NaN   \n",
       "Hair Academy Inc-New Carrollton             0.0         0       NaN       NaN   \n",
       "National College of Natural Medicine        0.0         0       NaN       NaN   \n",
       "\n",
       "                                      DISTANCEONLY     UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                       ...              \n",
       "Mesa Community College                         0.0  19055.0  ...     0.0205   \n",
       "Hair Academy Inc-New Carrollton                0.0    504.0  ...     0.0000   \n",
       "National College of Natural Medicine           0.0      NaN  ...        NaN   \n",
       "\n",
       "                                      UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                          \n",
       "Mesa Community College                  0.0257     0.0682    0.6457         1   \n",
       "Hair Academy Inc-New Carrollton         0.0000     0.0000    0.4683         1   \n",
       "National College of Natural Medicine       NaN        NaN       NaN         1   \n",
       "\n",
       "                                      PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                             \n",
       "Mesa Community College                 0.3423    0.2207   0.4010   \n",
       "Hair Academy Inc-New Carrollton        0.9756    1.0000   0.5882   \n",
       "National College of Natural Medicine      NaN       NaN      NaN   \n",
       "\n",
       "                                      MD_EARN_WNE_P10  GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                     \n",
       "Mesa Community College                          35200                8000  \n",
       "Hair Academy Inc-New Carrollton                 15200                9666  \n",
       "National College of Natural Medicine              NaN   PrivacySuppressed  \n",
       "\n",
       "[3 rows x 26 columns]"
      ]
     },
     "execution_count": 138,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Series和DataFrame都可以用标签进行切片。下面是对DataFrame用标签切片\n",
    "start = 'Mesa Community College'\n",
    "stop = 'Spokane Community College'\n",
    "college[start:stop:1500]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T09:08:27.130644Z",
     "start_time": "2019-10-30T09:08:27.121666Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Mesa Community College                            Mesa\n",
       "Hair Academy Inc-New Carrollton         New Carrollton\n",
       "National College of Natural Medicine          Portland\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 139,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city[start:stop:1500]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 更多"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "惰性切片不能用于列，只能用于DataFrame的行和Series，也不能同时选取行和\n",
    "列。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T09:10:32.988194Z",
     "start_time": "2019-10-30T09:10:32.890453Z"
    }
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'(slice(None, 10, None), ['CITY', 'STABBR'])' is an invalid key",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-140-97c2a34c13b7>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m# 下面尝试选取两列，导致错误\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mcollege\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m'CITY'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'STABBR'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\frame.py\u001b[0m in \u001b[0;36m__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   2925\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnlevels\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2926\u001b[0m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getitem_multilevel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2927\u001b[1;33m             \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2928\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mis_integer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mindexer\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2929\u001b[0m                 \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mindexer\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m   2655\u001b[0m                                  'backfill or nearest lookups')\n\u001b[0;32m   2656\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2657\u001b[1;33m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2658\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2659\u001b[0m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_maybe_cast_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mpandas/_libs/index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas/_libs/index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: '(slice(None, 10, None), ['CITY', 'STABBR'])' is an invalid key"
     ]
    }
   ],
   "source": [
    "# 下面尝试选取两列，导致错误\n",
    "college[:10, ['CITY', 'STABBR']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T09:12:51.809901Z",
     "start_time": "2019-10-30T09:12:51.791947Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>Normal</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>Birmingham</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Athens State University</th>\n",
       "      <td>Athens</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Auburn University at Montgomery</th>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Auburn University</th>\n",
       "      <td>Auburn</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                           CITY STABBR\n",
       "INSTNM                                                \n",
       "Alabama A & M University                 Normal     AL\n",
       "University of Alabama at Birmingham  Birmingham     AL\n",
       "Amridge University                   Montgomery     AL\n",
       "...                                         ...    ...\n",
       "Athens State University                  Athens     AL\n",
       "Auburn University at Montgomery      Montgomery     AL\n",
       "Auburn University                        Auburn     AL\n",
       "\n",
       "[10 rows x 2 columns]"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 只能用.loc .iloc选取\n",
    "first_ten_instnm = college.index[:10]\n",
    "college.loc[first_ten_instnm, ['CITY', 'STABBR']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.按照字母切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T09:13:47.939802Z",
     "start_time": "2019-10-30T09:13:47.753290Z"
    }
   },
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'Sp'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_slice_bound\u001b[1;34m(self, label, side, kind)\u001b[0m\n\u001b[0;32m   4804\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 4805\u001b[1;33m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_searchsorted_monotonic\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mside\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   4806\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36m_searchsorted_monotonic\u001b[1;34m(self, label, side)\u001b[0m\n\u001b[0;32m   4764\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 4765\u001b[1;33m         \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'index must be monotonic increasing or decreasing'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   4766\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: index must be monotonic increasing or decreasing",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-145-80910fe0be33>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m# 读取college数据集；尝试选取字母顺序在‘Sp’和‘Su’之间的学校\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mcollege\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread_csv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'data/college.csv'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mindex_col\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'INSTNM'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mcollege\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Sp'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;34m'Su'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   1498\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1499\u001b[0m             \u001b[0mmaybe_callable\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply_if_callable\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobj\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1500\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getitem_axis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmaybe_callable\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1501\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1502\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_is_scalar_access\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m_getitem_axis\u001b[1;34m(self, key, axis)\u001b[0m\n\u001b[0;32m   1865\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mslice\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1866\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_validate_key\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1867\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_slice_axis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1868\u001b[0m         \u001b[1;32melif\u001b[0m \u001b[0mcom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mis_bool_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1869\u001b[0m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getbool_axis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m_get_slice_axis\u001b[1;34m(self, slice_obj, axis)\u001b[0m\n\u001b[0;32m   1531\u001b[0m         \u001b[0mlabels\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mobj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_axis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1532\u001b[0m         indexer = labels.slice_indexer(slice_obj.start, slice_obj.stop,\n\u001b[1;32m-> 1533\u001b[1;33m                                        slice_obj.step, kind=self.name)\n\u001b[0m\u001b[0;32m   1534\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1535\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mindexer\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mslice\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mslice_indexer\u001b[1;34m(self, start, end, step, kind)\u001b[0m\n\u001b[0;32m   4671\u001b[0m         \"\"\"\n\u001b[0;32m   4672\u001b[0m         start_slice, end_slice = self.slice_locs(start, end, step=step,\n\u001b[1;32m-> 4673\u001b[1;33m                                                  kind=kind)\n\u001b[0m\u001b[0;32m   4674\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4675\u001b[0m         \u001b[1;31m# return a slice\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mslice_locs\u001b[1;34m(self, start, end, step, kind)\u001b[0m\n\u001b[0;32m   4870\u001b[0m         \u001b[0mstart_slice\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4871\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mstart\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 4872\u001b[1;33m             \u001b[0mstart_slice\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_slice_bound\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstart\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'left'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkind\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   4873\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mstart_slice\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4874\u001b[0m             \u001b[0mstart_slice\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_slice_bound\u001b[1;34m(self, label, side, kind)\u001b[0m\n\u001b[0;32m   4806\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4807\u001b[0m                 \u001b[1;31m# raise the original KeyError\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 4808\u001b[1;33m                 \u001b[1;32mraise\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   4809\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4810\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mslc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndarray\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_slice_bound\u001b[1;34m(self, label, side, kind)\u001b[0m\n\u001b[0;32m   4800\u001b[0m         \u001b[1;31m# we need to look up the label\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4801\u001b[0m         \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 4802\u001b[1;33m             \u001b[0mslc\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_loc_only_exact_matches\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   4803\u001b[0m         \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4804\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36m_get_loc_only_exact_matches\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   4770\u001b[0m         \u001b[0mget_slice_bound\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4771\u001b[0m         \"\"\"\n\u001b[1;32m-> 4772\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   4773\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4774\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mget_slice_bound\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mside\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkind\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m   2657\u001b[0m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2658\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2659\u001b[1;33m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_maybe_cast_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2660\u001b[0m         \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtolerance\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtolerance\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2661\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mindexer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mindexer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msize\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mpandas/_libs/index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas/_libs/index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas/_libs/hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas/_libs/hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: 'Sp'"
     ]
    }
   ],
   "source": [
    "# 读取college数据集；尝试选取字母顺序在‘Sp’和‘Su’之间的学校\n",
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "college.loc['Sp':'Su']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T09:15:38.727205Z",
     "start_time": "2019-10-30T09:15:38.673349Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A &amp; W Healthcare Educators</th>\n",
       "      <td>New Orleans</td>\n",
       "      <td>LA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.1250</td>\n",
       "      <td>1</td>\n",
       "      <td>0.7018</td>\n",
       "      <td>0.8596</td>\n",
       "      <td>0.6667</td>\n",
       "      <td>NaN</td>\n",
       "      <td>19022.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A T Still University of Health Sciences</th>\n",
       "      <td>Kirksville</td>\n",
       "      <td>MO</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>219800</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ABC Beauty Academy</th>\n",
       "      <td>Garland</td>\n",
       "      <td>TX</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0.7857</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.8286</td>\n",
       "      <td>NaN</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ABC Beauty College Inc</th>\n",
       "      <td>Arkadelphia</td>\n",
       "      <td>AR</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>38.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.2105</td>\n",
       "      <td>1</td>\n",
       "      <td>0.9815</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.4688</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "      <td>16500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AI Miami International University of Art and Design</th>\n",
       "      <td>Miami</td>\n",
       "      <td>FL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2778.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0018</td>\n",
       "      <td>0.0025</td>\n",
       "      <td>0.4644</td>\n",
       "      <td>0.2185</td>\n",
       "      <td>1</td>\n",
       "      <td>0.5507</td>\n",
       "      <td>0.6966</td>\n",
       "      <td>0.3262</td>\n",
       "      <td>29900</td>\n",
       "      <td>31000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                           CITY STABBR  HBCU  \\\n",
       "INSTNM                                                                         \n",
       "A & W Healthcare Educators                          New Orleans     LA   0.0   \n",
       "A T Still University of Health Sciences              Kirksville     MO   0.0   \n",
       "ABC Beauty Academy                                      Garland     TX   0.0   \n",
       "ABC Beauty College Inc                              Arkadelphia     AR   0.0   \n",
       "AI Miami International University of Art and De...        Miami     FL   0.0   \n",
       "\n",
       "                                                    MENONLY  WOMENONLY  \\\n",
       "INSTNM                                                                   \n",
       "A & W Healthcare Educators                              0.0        0.0   \n",
       "A T Still University of Health Sciences                 0.0        0.0   \n",
       "ABC Beauty Academy                                      0.0        0.0   \n",
       "ABC Beauty College Inc                                  0.0        0.0   \n",
       "AI Miami International University of Art and De...      0.0        0.0   \n",
       "\n",
       "                                                    RELAFFIL  SATVRMID  \\\n",
       "INSTNM                                                                   \n",
       "A & W Healthcare Educators                                 0       NaN   \n",
       "A T Still University of Health Sciences                    0       NaN   \n",
       "ABC Beauty Academy                                         0       NaN   \n",
       "ABC Beauty College Inc                                     0       NaN   \n",
       "AI Miami International University of Art and De...         0       NaN   \n",
       "\n",
       "                                                    SATMTMID  DISTANCEONLY  \\\n",
       "INSTNM                                                                       \n",
       "A & W Healthcare Educators                               NaN           0.0   \n",
       "A T Still University of Health Sciences                  NaN           0.0   \n",
       "ABC Beauty Academy                                       NaN           0.0   \n",
       "ABC Beauty College Inc                                   NaN           0.0   \n",
       "AI Miami International University of Art and De...       NaN           0.0   \n",
       "\n",
       "                                                      UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                      ...              \n",
       "A & W Healthcare Educators                            40.0  ...     0.0000   \n",
       "A T Still University of Health Sciences                NaN  ...        NaN   \n",
       "ABC Beauty Academy                                    30.0  ...     0.0000   \n",
       "ABC Beauty College Inc                                38.0  ...     0.0000   \n",
       "AI Miami International University of Art and De...  2778.0  ...     0.0018   \n",
       "\n",
       "                                                    UGDS_NRA  UGDS_UNKN  \\\n",
       "INSTNM                                                                    \n",
       "A & W Healthcare Educators                            0.0000     0.0000   \n",
       "A T Still University of Health Sciences                  NaN        NaN   \n",
       "ABC Beauty Academy                                    0.0000     0.0000   \n",
       "ABC Beauty College Inc                                0.0000     0.0000   \n",
       "AI Miami International University of Art and De...    0.0025     0.4644   \n",
       "\n",
       "                                                    PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                   \n",
       "A & W Healthcare Educators                            0.1250         1   \n",
       "A T Still University of Health Sciences                  NaN         1   \n",
       "ABC Beauty Academy                                    0.0000         0   \n",
       "ABC Beauty College Inc                                0.2105         1   \n",
       "AI Miami International University of Art and De...    0.2185         1   \n",
       "\n",
       "                                                    PCTPELL  PCTFLOAN  \\\n",
       "INSTNM                                                                  \n",
       "A & W Healthcare Educators                           0.7018    0.8596   \n",
       "A T Still University of Health Sciences                 NaN       NaN   \n",
       "ABC Beauty Academy                                   0.7857    0.0000   \n",
       "ABC Beauty College Inc                               0.9815    1.0000   \n",
       "AI Miami International University of Art and De...   0.5507    0.6966   \n",
       "\n",
       "                                                    UG25ABV  \\\n",
       "INSTNM                                                        \n",
       "A & W Healthcare Educators                           0.6667   \n",
       "A T Still University of Health Sciences                 NaN   \n",
       "ABC Beauty Academy                                   0.8286   \n",
       "ABC Beauty College Inc                               0.4688   \n",
       "AI Miami International University of Art and De...   0.3262   \n",
       "\n",
       "                                                      MD_EARN_WNE_P10  \\\n",
       "INSTNM                                                                  \n",
       "A & W Healthcare Educators                                        NaN   \n",
       "A T Still University of Health Sciences                        219800   \n",
       "ABC Beauty Academy                                                NaN   \n",
       "ABC Beauty College Inc                              PrivacySuppressed   \n",
       "AI Miami International University of Art and De...              29900   \n",
       "\n",
       "                                                    GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                  \n",
       "A & W Healthcare Educators                                     19022.5  \n",
       "A T Still University of Health Sciences              PrivacySuppressed  \n",
       "ABC Beauty Academy                                   PrivacySuppressed  \n",
       "ABC Beauty College Inc                                           16500  \n",
       "AI Miami International University of Art and De...               31000  \n",
       "\n",
       "[5 rows x 26 columns]"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对college进行排序\n",
    "college = college.sort_index()\n",
    "college.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T09:16:23.337902Z",
     "start_time": "2019-10-30T09:16:23.282070Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Spa Tech Institute-Ipswich</th>\n",
       "      <td>Ipswich</td>\n",
       "      <td>MA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0541</td>\n",
       "      <td>0.4054</td>\n",
       "      <td>1</td>\n",
       "      <td>0.2656</td>\n",
       "      <td>0.3906</td>\n",
       "      <td>0.7907</td>\n",
       "      <td>21500</td>\n",
       "      <td>6333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spa Tech Institute-Plymouth</th>\n",
       "      <td>Plymouth</td>\n",
       "      <td>MA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>153.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2484</td>\n",
       "      <td>0.3399</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3716</td>\n",
       "      <td>0.4266</td>\n",
       "      <td>0.6250</td>\n",
       "      <td>21500</td>\n",
       "      <td>6333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spa Tech Institute-Westboro</th>\n",
       "      <td>Westboro</td>\n",
       "      <td>MA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0222</td>\n",
       "      <td>0.5778</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3409</td>\n",
       "      <td>0.4545</td>\n",
       "      <td>0.6882</td>\n",
       "      <td>21500</td>\n",
       "      <td>6333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stylemaster College of Hair Design</th>\n",
       "      <td>Longview</td>\n",
       "      <td>WA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>77.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.013</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>0.8036</td>\n",
       "      <td>0.7024</td>\n",
       "      <td>0.4510</td>\n",
       "      <td>17000</td>\n",
       "      <td>13320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Styles and Profiles Beauty College</th>\n",
       "      <td>Selmer</td>\n",
       "      <td>TN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>31.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>0.8182</td>\n",
       "      <td>0.7955</td>\n",
       "      <td>0.2400</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Styletrends Barber and Hairstyling Academy</th>\n",
       "      <td>Rock Hill</td>\n",
       "      <td>SC</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.5556</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.3529</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "      <td>9495.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>201 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                 CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                        \n",
       "Spa Tech Institute-Ipswich                    Ipswich     MA   0.0      0.0   \n",
       "Spa Tech Institute-Plymouth                  Plymouth     MA   0.0      0.0   \n",
       "Spa Tech Institute-Westboro                  Westboro     MA   0.0      0.0   \n",
       "...                                               ...    ...   ...      ...   \n",
       "Stylemaster College of Hair Design           Longview     WA   0.0      0.0   \n",
       "Styles and Profiles Beauty College             Selmer     TN   0.0      0.0   \n",
       "Styletrends Barber and Hairstyling Academy  Rock Hill     SC   0.0      0.0   \n",
       "\n",
       "                                            WOMENONLY  RELAFFIL  SATVRMID  \\\n",
       "INSTNM                                                                      \n",
       "Spa Tech Institute-Ipswich                        0.0         0       NaN   \n",
       "Spa Tech Institute-Plymouth                       0.0         0       NaN   \n",
       "Spa Tech Institute-Westboro                       0.0         0       NaN   \n",
       "...                                               ...       ...       ...   \n",
       "Stylemaster College of Hair Design                0.0         0       NaN   \n",
       "Styles and Profiles Beauty College                0.0         0       NaN   \n",
       "Styletrends Barber and Hairstyling Academy        0.0         0       NaN   \n",
       "\n",
       "                                            SATMTMID  DISTANCEONLY   UGDS  \\\n",
       "INSTNM                                                                      \n",
       "Spa Tech Institute-Ipswich                       NaN           0.0   37.0   \n",
       "Spa Tech Institute-Plymouth                      NaN           0.0  153.0   \n",
       "Spa Tech Institute-Westboro                      NaN           0.0   90.0   \n",
       "...                                              ...           ...    ...   \n",
       "Stylemaster College of Hair Design               NaN           0.0   77.0   \n",
       "Styles and Profiles Beauty College               NaN           0.0   31.0   \n",
       "Styletrends Barber and Hairstyling Academy       NaN           0.0   45.0   \n",
       "\n",
       "                                            ...  UGDS_2MOR  UGDS_NRA  \\\n",
       "INSTNM                                      ...                        \n",
       "Spa Tech Institute-Ipswich                  ...      0.000       0.0   \n",
       "Spa Tech Institute-Plymouth                 ...      0.000       0.0   \n",
       "Spa Tech Institute-Westboro                 ...      0.000       0.0   \n",
       "...                                         ...        ...       ...   \n",
       "Stylemaster College of Hair Design          ...      0.013       0.0   \n",
       "Styles and Profiles Beauty College          ...      0.000       0.0   \n",
       "Styletrends Barber and Hairstyling Academy  ...      0.000       0.0   \n",
       "\n",
       "                                            UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                      \n",
       "Spa Tech Institute-Ipswich                     0.0541    0.4054         1   \n",
       "Spa Tech Institute-Plymouth                    0.2484    0.3399         1   \n",
       "Spa Tech Institute-Westboro                    0.0222    0.5778         1   \n",
       "...                                               ...       ...       ...   \n",
       "Stylemaster College of Hair Design             0.0000    0.0000         1   \n",
       "Styles and Profiles Beauty College             0.0000    0.0000         1   \n",
       "Styletrends Barber and Hairstyling Academy     0.0000    0.5556         0   \n",
       "\n",
       "                                            PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                                   \n",
       "Spa Tech Institute-Ipswich                   0.2656    0.3906   0.7907   \n",
       "Spa Tech Institute-Plymouth                  0.3716    0.4266   0.6250   \n",
       "Spa Tech Institute-Westboro                  0.3409    0.4545   0.6882   \n",
       "...                                             ...       ...      ...   \n",
       "Stylemaster College of Hair Design           0.8036    0.7024   0.4510   \n",
       "Styles and Profiles Beauty College           0.8182    0.7955   0.2400   \n",
       "Styletrends Barber and Hairstyling Academy   1.0000    1.0000   0.3529   \n",
       "\n",
       "                                              MD_EARN_WNE_P10  \\\n",
       "INSTNM                                                          \n",
       "Spa Tech Institute-Ipswich                              21500   \n",
       "Spa Tech Institute-Plymouth                             21500   \n",
       "Spa Tech Institute-Westboro                             21500   \n",
       "...                                                       ...   \n",
       "Stylemaster College of Hair Design                      17000   \n",
       "Styles and Profiles Beauty College          PrivacySuppressed   \n",
       "Styletrends Barber and Hairstyling Academy  PrivacySuppressed   \n",
       "\n",
       "                                            GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                          \n",
       "Spa Tech Institute-Ipswich                                6333  \n",
       "Spa Tech Institute-Plymouth                               6333  \n",
       "Spa Tech Institute-Westboro                               6333  \n",
       "...                                                        ...  \n",
       "Stylemaster College of Hair Design                       13320  \n",
       "Styles and Profiles Beauty College           PrivacySuppressed  \n",
       "Styletrends Barber and Hairstyling Academy              9495.5  \n",
       "\n",
       "[201 rows x 26 columns]"
      ]
     },
     "execution_count": 147,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 再尝试选取字母顺序在‘Sp’和‘Su’之间的学校\n",
    "pd.options.display.max_rows = 6\n",
    "college.loc['Sp':'Su']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T09:17:09.110497Z",
     "start_time": "2019-10-30T09:17:09.105506Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 148,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.index.is_monotonic_decreasing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T09:21:43.930540Z",
     "start_time": "2019-10-30T09:21:43.918571Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 165,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 可以用is_monotonic_increasing或is_monotonic_decreasing检测字母排序的顺序\n",
    "college = college.sort_index(ascending=True)\n",
    "college.index.is_monotonic_increasing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T09:21:45.665900Z",
     "start_time": "2019-10-30T09:21:45.611045Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A &amp; W Healthcare Educators</th>\n",
       "      <td>New Orleans</td>\n",
       "      <td>LA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.1250</td>\n",
       "      <td>1</td>\n",
       "      <td>0.7018</td>\n",
       "      <td>0.8596</td>\n",
       "      <td>0.6667</td>\n",
       "      <td>NaN</td>\n",
       "      <td>19022.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A T Still University of Health Sciences</th>\n",
       "      <td>Kirksville</td>\n",
       "      <td>MO</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>219800</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ABC Beauty Academy</th>\n",
       "      <td>Garland</td>\n",
       "      <td>TX</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0.7857</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.8286</td>\n",
       "      <td>NaN</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zane State College</th>\n",
       "      <td>Zanesville</td>\n",
       "      <td>OH</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2063.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0218</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2399</td>\n",
       "      <td>0.5730</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3645</td>\n",
       "      <td>0.3434</td>\n",
       "      <td>0.3185</td>\n",
       "      <td>23800</td>\n",
       "      <td>13960.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>duCret School of Arts</th>\n",
       "      <td>Plainfield</td>\n",
       "      <td>NJ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>41.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0976</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0244</td>\n",
       "      <td>0.4146</td>\n",
       "      <td>1</td>\n",
       "      <td>0.4375</td>\n",
       "      <td>0.5000</td>\n",
       "      <td>0.1250</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eClips School of Cosmetology and Barbering</th>\n",
       "      <td>Cape Girardeau</td>\n",
       "      <td>MO</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>83.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>0.9496</td>\n",
       "      <td>0.9832</td>\n",
       "      <td>0.3772</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "      <td>9500</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>7535 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                      CITY STABBR  HBCU  \\\n",
       "INSTNM                                                                    \n",
       "A & W Healthcare Educators                     New Orleans     LA   0.0   \n",
       "A T Still University of Health Sciences         Kirksville     MO   0.0   \n",
       "ABC Beauty Academy                                 Garland     TX   0.0   \n",
       "...                                                    ...    ...   ...   \n",
       "Zane State College                              Zanesville     OH   0.0   \n",
       "duCret School of Arts                           Plainfield     NJ   0.0   \n",
       "eClips School of Cosmetology and Barbering  Cape Girardeau     MO   0.0   \n",
       "\n",
       "                                            MENONLY  WOMENONLY  RELAFFIL  \\\n",
       "INSTNM                                                                     \n",
       "A & W Healthcare Educators                      0.0        0.0         0   \n",
       "A T Still University of Health Sciences         0.0        0.0         0   \n",
       "ABC Beauty Academy                              0.0        0.0         0   \n",
       "...                                             ...        ...       ...   \n",
       "Zane State College                              0.0        0.0         0   \n",
       "duCret School of Arts                           0.0        0.0         0   \n",
       "eClips School of Cosmetology and Barbering      0.0        0.0         0   \n",
       "\n",
       "                                            SATVRMID  SATMTMID  DISTANCEONLY  \\\n",
       "INSTNM                                                                         \n",
       "A & W Healthcare Educators                       NaN       NaN           0.0   \n",
       "A T Still University of Health Sciences          NaN       NaN           0.0   \n",
       "ABC Beauty Academy                               NaN       NaN           0.0   \n",
       "...                                              ...       ...           ...   \n",
       "Zane State College                               NaN       NaN           0.0   \n",
       "duCret School of Arts                            NaN       NaN           0.0   \n",
       "eClips School of Cosmetology and Barbering       NaN       NaN           0.0   \n",
       "\n",
       "                                              UGDS  ...  UGDS_2MOR  UGDS_NRA  \\\n",
       "INSTNM                                              ...                        \n",
       "A & W Healthcare Educators                    40.0  ...     0.0000       0.0   \n",
       "A T Still University of Health Sciences        NaN  ...        NaN       NaN   \n",
       "ABC Beauty Academy                            30.0  ...     0.0000       0.0   \n",
       "...                                            ...  ...        ...       ...   \n",
       "Zane State College                          2063.0  ...     0.0218       0.0   \n",
       "duCret School of Arts                         41.0  ...     0.0976       0.0   \n",
       "eClips School of Cosmetology and Barbering    83.0  ...     0.0000       0.0   \n",
       "\n",
       "                                            UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                      \n",
       "A & W Healthcare Educators                     0.0000    0.1250         1   \n",
       "A T Still University of Health Sciences           NaN       NaN         1   \n",
       "ABC Beauty Academy                             0.0000    0.0000         0   \n",
       "...                                               ...       ...       ...   \n",
       "Zane State College                             0.2399    0.5730         1   \n",
       "duCret School of Arts                          0.0244    0.4146         1   \n",
       "eClips School of Cosmetology and Barbering     0.0000    0.0000         1   \n",
       "\n",
       "                                            PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                                   \n",
       "A & W Healthcare Educators                   0.7018    0.8596   0.6667   \n",
       "A T Still University of Health Sciences         NaN       NaN      NaN   \n",
       "ABC Beauty Academy                           0.7857    0.0000   0.8286   \n",
       "...                                             ...       ...      ...   \n",
       "Zane State College                           0.3645    0.3434   0.3185   \n",
       "duCret School of Arts                        0.4375    0.5000   0.1250   \n",
       "eClips School of Cosmetology and Barbering   0.9496    0.9832   0.3772   \n",
       "\n",
       "                                              MD_EARN_WNE_P10  \\\n",
       "INSTNM                                                          \n",
       "A & W Healthcare Educators                                NaN   \n",
       "A T Still University of Health Sciences                219800   \n",
       "ABC Beauty Academy                                        NaN   \n",
       "...                                                       ...   \n",
       "Zane State College                                      23800   \n",
       "duCret School of Arts                       PrivacySuppressed   \n",
       "eClips School of Cosmetology and Barbering  PrivacySuppressed   \n",
       "\n",
       "                                            GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                          \n",
       "A & W Healthcare Educators                             19022.5  \n",
       "A T Still University of Health Sciences      PrivacySuppressed  \n",
       "ABC Beauty Academy                           PrivacySuppressed  \n",
       "...                                                        ...  \n",
       "Zane State College                                     13960.5  \n",
       "duCret School of Arts                        PrivacySuppressed  \n",
       "eClips School of Cosmetology and Barbering                9500  \n",
       "\n",
       "[7535 rows x 26 columns]"
      ]
     },
     "execution_count": 166,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-30T09:21:54.148215Z",
     "start_time": "2019-10-30T09:21:54.121287Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>0 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [CITY, STABBR, HBCU, MENONLY, WOMENONLY, RELAFFIL, SATVRMID, SATMTMID, DISTANCEONLY, UGDS, UGDS_WHITE, UGDS_BLACK, UGDS_HISP, UGDS_ASIAN, UGDS_AIAN, UGDS_NHPI, UGDS_2MOR, UGDS_NRA, UGDS_UNKN, PPTUG_EF, CURROPER, PCTPELL, PCTFLOAN, UG25ABV, MD_EARN_WNE_P10, GRAD_DEBT_MDN_SUPP]\n",
       "Index: []\n",
       "\n",
       "[0 rows x 26 columns]"
      ]
     },
     "execution_count": 167,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字母逆序选取\n",
    "college.loc['E':'B']"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
